<?php
/**
 * 【收获地址模块】列表接口 
 * @author webopenfather
 */

// 导入公共库文件
include '../../util/function.php';
include '../../util/db.php';
include '../../util/token.php';// 这个文件中声明了$userId

// 1. 接受数据（无）

// 2. 操作数据库（注：$pdo变量在db.php文件中定义了 所以可以直接用）
$pdoStatement = $pdo->query("select * from ecs_user_address where user_id = {$userId}");
$datas = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);


// 城市过滤
$temp = [];
foreach($datas as $k=>$data) 
{
    //图片表
    $pdoStatement = $pdo->query("select * from ecs_region where region_id = {$data['country']}");
    $country = $pdoStatement->fetch(PDO::FETCH_ASSOC);
    $pdoStatement = $pdo->query("select * from ecs_region where region_id = {$data['province']}");
    $province = $pdoStatement->fetch(PDO::FETCH_ASSOC);
    $pdoStatement = $pdo->query("select * from ecs_region where region_id = {$data['city']}");
    $city = $pdoStatement->fetch(PDO::FETCH_ASSOC);
    $pdoStatement = $pdo->query("select * from ecs_region where region_id = {$data['district']}");
    $district = $pdoStatement->fetch(PDO::FETCH_ASSOC);

    $data['countryName'] = $country['region_name'];
    $data['provinceName'] = $province['region_name'];
    $data['cityName'] = $city['region_name'];
    $data['districtName'] = $district['region_name'];
    $temp[] = $data;
}

// 3. 响应数据
response(200, '操作成功', $temp);